package main

import "fmt"

func swap(a int, b int) {
	var temp int
	temp = a
	a = b
	b = temp
}

func swap1(pa *int, pb *int) {
	var temp int
	temp = *pa // temp = main::a
	*pa = *pb  // main::a = main::b
	*pb = temp // main::b = temp
}

func main() {

	var a int = 10
	var b int = 20

	var d int = 30

	swap(a, b)

	fmt.Println("this is swap  ========>", "a = ", a, " b = ", b)

	swap1(&a, &b)

	fmt.Println("this is swap1  ========>", "a = ", a, " b = ", b)

	var p *int

	p = &a
	fmt.Println(&a) // 0xc00000a0d8    地址
	fmt.Println(p)  // 0xc00000a0d8    地址

	var pp **int // 二级指针

	pp = &p

	fmt.Println(&p) // 0xc000090050
	fmt.Println(pp) // 0xc000090050

	// then give var of c
	var c int = 100
	p = &c

	fmt.Println("this is c before modify", c)
	fmt.Println("this is p after modify", *p)

	*p = d

	fmt.Println("this is c after modify", c)
	fmt.Println("this is p after modify", *p)
}
